package com.lc.cehui.ui.activity.home;

import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.hjq.bar.TitleBar;
import com.hjq.http.EasyHttp;
import com.hjq.http.listener.HttpCallback;
import com.lc.cehui.R;
import com.lc.cehui.app.AppActivity;
import com.lc.cehui.http.request.CompanyChildtypeShowmoreApi;
import com.lc.cehui.http.response.CompanyChildtypeShowmoreBean;
import com.lc.cehui.other.IntentKey;
import com.lc.cehui.util.CourseUtils;
import com.lc.cehui.util.SPUtil;

import org.jetbrains.annotations.NotNull;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;

public class ChildtypeShowmoreActivity extends AppActivity {
    @BindView(R.id.titleBar)
    TitleBar titleBar;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    private BaseQuickAdapter projectadapter;
    private int layout;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_childtypeshowmore;
    }

    @Override
    protected void initView() {
       titleBar.setTitle(getIntent().getStringExtra("title"));
       if (getIntent().getStringExtra("type").equals("1")){
           layout = R.layout.item_project_experience;
       }else {
           layout =R.layout.item_experience;
       }
       recyclerView.setLayoutManager(new LinearLayoutManager(this));
        projectadapter = new BaseQuickAdapter<CompanyChildtypeShowmoreBean.DataBean, BaseViewHolder>(layout) {
            @Override
            protected void convert(@NotNull BaseViewHolder holder, CompanyChildtypeShowmoreBean.DataBean bean) {
              TextView tv_content= holder.getView(R.id.tv_content);
              tv_content.setMaxLines(1000);
           if (getIntent().getStringExtra("type").equals("1")){
               holder.setText(R.id.tv_name,bean.getTitle());
               holder.setText(R.id.tv_year, CourseUtils.getMillsToTime(bean.getStart_time())+"至"+CourseUtils.getMillsToTime(bean.getEnd_time()));
               holder.setText(R.id.tv_content,bean.getContent());
           }else {
               holder.setText(R.id.tv_name,bean.getTitle());
               holder.setText(R.id.tv_tag,bean.getName());
               holder.setText(R.id.tv_year, CourseUtils.getMillsToTime(bean.getStart_time())+"至"+CourseUtils.getMillsToTime(bean.getEnd_time()));
               holder.setText(R.id.tv_content,bean.getContent());
               holder.setText(R.id.tv_salary,bean.getSalary());
           }


            }
        };
        recyclerView.setAdapter(projectadapter);
    }

    @Override
    protected void initData() {
        company_childtype_showmore();
    }

    private void company_childtype_showmore() {
        EasyHttp.post(this)
                .api(new CompanyChildtypeShowmoreApi().setJob_id(getIntent().getStringExtra("id")).setUserid(SPUtil.get(this, IntentKey.USERID,0)).setType(getIntent().getStringExtra("type")))
                .request(new HttpCallback<CompanyChildtypeShowmoreBean>(this) {

                    @Override
                    public void onSucceed(CompanyChildtypeShowmoreBean data) {

                        if (data.getCode().equals("200")) {

                         projectadapter.setNewData(data.getData());
                         projectadapter.notifyDataSetChanged();

                        }

                    }
                });
    }
}
